package com.databias.j15.perfmon;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import com.databias.j15.GScreen;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * This class allows a G15 Java application to be tested to the screen by simulating a 
 * keyboard LCD screen at 5x the resolution.
 * 
 * It is constructed by passing in a screen collection object (GScreen).  When instantiated,
 * it will be repainted by the system as needed, but needs to be periodically updated by
 * calling a frame.repaint().
 * 
 * @author ffarzanegan
 *
 */

public class G15DebugScreen extends JFrame{
	
	
	/**
	 * This inner class extends a JPanel for debugging purposes.  
	 * It is easily used by being placed inside a JFrame.
	 * 
	 * The screen returned by this function is scaled to 5x the G15 LCD screen
	 * This is done via a transformation and is used to match the outer frame resolution.
	 * 
	 * @author ffarzanegan
	 *
	 */
	private class ShapePanel extends JPanel
	{
		/**
		 * Keep a copy of our container class
		 */
		private GScreen gs;
		
		ShapePanel (GScreen gscreen)
		{
			// Set our collection object
			gs=gscreen;
		}
			
		/**
		 * This method is inherited and is called by the system thread for different reasons
		 * http://java.sun.com/products/jfc/tsc/articles/painting/index.html
		 * 
		 * and is the only place that actual draw functions should be done.
		 */
	      public void paintComponent( Graphics g )
	      {
	    	  
	        //super.paintComponent( g ); // call superclass's paintComponent- no need in swing
	        Graphics2D g2d = ( Graphics2D ) g;  // Is this needed if I have the gscreen already?
	        
	        // What I may need to do at this point is an affine xform on the whole screen
	        g2d.scale(5,5);


	        // Set our screen for our collection
	        gs.setScreen(g2d);
	        
	        // Draw them.
	        gs.draw();
	        
	      }
		
	} // GPanel class
	
	/**
	 * Create a JFrame to display a GScreen collection.
	 * 
	 * @param title Window title (String)
	 * @param screen GScreen (screen attribute should not be set as it is set in the inner panel)
	 */
	G15DebugScreen (String title, GScreen screen)
	{
		super(title);
		
		this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		ShapePanel sp = new ShapePanel(screen);
		this.add( sp ); // add  to frame
		this.setBackground( Color.WHITE ); // set frame background color
		this.setSize(800,260); // set frame size  160, 43
		this.setVisible( true ); // display frame
	}

}
